﻿@inject IWebHelper webHelper
@inject IWorkContext workContext
@inject IPermissionService permissionService
@inject CommonSettings commonSettings
@inject CustomerSettings customerSettings
@inject LocalizationSettings localizationSettings
@inject AdminAreaSettings adminAreaSettings
@inject Grand.Core.Configuration.GrandConfig grandConfig

@using System.Text.Encodings.Web
@using Grand.Core.Domain.Customers
@using Grand.Framework.UI;
@using Grand.Core;
@using Grand.Core.Domain.Localization
@using Grand.Services.Security;
@using Grand.Core.Domain.Common;
@{
    var currentCustomer = workContext.CurrentCustomer;
    var usernamesEnabled = customerSettings.UsernamesEnabled;
    var currentVersion = GrandVersion.CurrentVersion;
    var kendoVersion = "2019.2.514";
    var supportRtl = workContext.WorkingLanguage.Rtl &&
        !localizationSettings.IgnoreRtlPropertyForAdminArea;

    //CSS
    if (supportRtl)
    {
        Html.AppendCssFileParts(string.Format("~/content/kendo/{0}/kendo.rtl.min.css", kendoVersion), excludeFromBundle: true);
        Html.AppendCssFileParts("~/administration/build/css/custom-rtl.css", excludeFromBundle: true);
        Html.AppendCssFileParts("~/administration/bootstrap/css/bootstrap-rtl.min.css", excludeFromBundle: true);
    }
    else
    {
        Html.AppendCssFileParts("~/administration/build/css/custom.css", excludeFromBundle: true);
    }
    Html.AppendCssFileParts(string.Format("~/content/kendo/{0}/kendo.common-material.min.css", kendoVersion), excludeFromBundle: true);
    Html.AppendCssFileParts($"~/content/kendo/{kendoVersion}/kendo.material.min.css", excludeFromBundle: true);
    Html.AppendCssFileParts($"~/content/kendo/{kendoVersion}/kendo.material.mobile.min.css", excludeFromBundle: true);
    Html.AppendCssFileParts("~/content/jquery-ui-themes/smoothness/jquery-ui-1.10.3.custom.min.css", excludeFromBundle: true);
    Html.AddScriptParts(location: ResourceLocation.Footer, src: "~/content/tinymce/tinymce.min.js", excludeFromBundle: true);

    //administration

    Html.AppendScriptParts(location: ResourceLocation.Footer, src: "~/administration/build/js/custom.js", excludeFromBundle: true);
    Html.AppendScriptParts(location: ResourceLocation.Footer, src: "~/administration/build/js/smartresize.js", excludeFromBundle: true);

    //vendors

    Html.AppendScriptParts(location: ResourceLocation.Footer, src: "~/administration/bootstrap/js/bootstrap.min.js", excludeFromBundle: true);
    Html.AppendCssFileParts("~/administration/bootstrap/css/bootstrap.min.css", excludeFromBundle: true);


    //js
    //available list of culture https://github.com/telerik/kendo-ui-core/tree/master/src/cultures
    Html.AppendScriptParts(string.Format("~/scripts/kendo/{0}/cultures/kendo.culture.{1}.min.js", kendoVersion, "en-US"), excludeFromBundle: true);
    Html.AppendScriptParts(string.Format("~/scripts/kendo/{0}/kendo.grid.js", kendoVersion), excludeFromBundle: true);
    Html.AppendScriptParts(string.Format("~/scripts/kendo/{0}/kendo.ui.core.min.js", kendoVersion), excludeFromBundle: true);
    Html.AppendScriptParts("~/scripts/admin.common.js", excludeFromBundle: true);
    Html.AppendScriptParts("~/scripts/jquery-ui-1.12.1.custom/jquery-ui.min.js", excludeFromBundle: true);
    Html.AppendScriptParts("~/scripts/jquery.validate.unobtrusive.min.js", excludeFromBundle: true);
    Html.AppendScriptParts("~/scripts/jquery.validate.min.js", excludeFromBundle: true);
    Html.AppendScriptParts("~/scripts/admin.search.js", excludeFromBundle: true);
    Html.AppendScriptParts("~/scripts/typeahead.js", excludeFromBundle: true);

    Html.AppendCssFileParts("~/administration/simple-line-icons/simple-line-icons.min.css", excludeFromBundle: true);
    Html.AppendCssFileParts("~/administration/build/css/font-awesome.min.css", excludeFromBundle: true);
    Html.AppendScriptParts(location: ResourceLocation.Head, src: "~/administration/bootstrap/js/daterangepicker.min.js", excludeFromBundle: true);
    Html.AppendCssFileParts("~/administration/bootstrap/css/daterangepicker.min.css", excludeFromBundle: true);
    Html.AppendScriptParts("~/administration/build/js/moment.min.js", excludeFromBundle: true);
    Html.AppendScriptParts("~/administration/build/js/jquery.min.js", excludeFromBundle: true);

    //page title
    string adminPageTitle = "";
    if (!String.IsNullOrWhiteSpace(ViewBag.Title))
    {
        adminPageTitle = ViewBag.Title + " / ";
    }
    adminPageTitle += T("Admin.PageTitle").Text;

    //has "Manage Maintenance" permission?
    var canManageMaintenance = await permissionService.Authorize(StandardPermissionProvider.ManageMaintenance);

    //X-UA-Compatible tag
    if (commonSettings.RenderXuaCompatible)
    {
        Html.AppendHeadCustomParts(string.Format("<meta http-equiv=\"X-UA-Compatible\" content=\"{0}\"/>", commonSettings.XuaCompatibleValue));
    }

}
<!DOCTYPE html>
<html @if (supportRtl) { <text> dir="rtl" </text> } onloadstart="myFunction()">
<head>
    <title>@adminPageTitle</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    @Html.GrandHeadCustom()
    @Html.GrandCssFiles(this.Url, ResourceLocation.Head, false)
    @Html.GrandScripts(this.Url, ResourceLocation.Head, false)
</head>
<body>
    @Html.AntiForgeryToken()
    <script>
        if (document.readyState == "loading") {
            let value = localStorage.getItem("sideBarCookie");
            if (value == "true") {
                $('body').removeClass('nav-md');
                $('body').addClass('nav-sm');
                $(".site_title").css("padding-left", "26px");
                if ($('body').hasClass('nav-sm')) {
                    $('#sidebar-menu').find('li.active').addClass('active-sm').removeClass('active');
                    $('#sidebar-menu').find('li.active-sm ul').hide();
                }
            }
            else {
                $('body').removeClass('nav-sm');
                $('body').addClass('nav-md');
                $(".site_title").css("padding-left", "0px");
                $('#sidebar-menu').find('li.active-sm').addClass('active').removeClass('active-sm');
                $('#sidebar-menu').find('li.active > ul').show();
            }
        }

    </script>
    <div class="container body">
        <div class="main_container">
            <vc:admin-widget widget-zone="admin_header_before" additional-data="null" />
            @if (IsSectionDefined("headermenu"))
            {
                @RenderSection("headermenu")
            }
            else
            {
                <partial name="Menu" />
            }
            <vc:admin-widget widget-zone="admin_header_after" additional-data="null" />
            @if (IsSectionDefined("statusbar"))
            {
                @RenderSection("statusbar")
            }
            @if (IsSectionDefined("header"))
            {
                @RenderSection("header")
            }
            else
            {
                <vc:admin-widget widget-zone="header_before" additional-data="null" />
                <div class="top_nav">
                    <div class="nav_menu">
                        <nav>
                            <div class="nav toggle">
                                <a id="menu_toggle"><i class="fa fa-bars"></i></a>
                            </div>

                            @if (currentCustomer.IsAdmin())
                            {
                                <div class="admin-search-input-container">
                                    <input id="searchInput" type="text" class="form-control" placeholder="@T("Admin.AdminSearch.Placeholder")">
                                    <script>
                                      $(document).ready(function () {
                                        Admin.Search.init("@(Url.Action("Search", "AdminSearch"))");
                                      });
                                    </script>
                                </div>
                            }
                            <vc:admin-widget widget-zone="header_toggle_after" additional-data="null" />
                            <ul class="nav navbar-nav navbar-right">

                                <li class="dropdown" role="presentation">
                                    <a href="@Url.Action("Index", "Home", new { area = "" })" class="dropdown-toggle">
                                        <i class="icon-home"></i>
                                    </a>
                                </li>
                                <li role="presentation" class="dropdown">
                                    <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                                        <i class="icon-info"></i>
                                    </a>
                                    <ul id="menu1" class="dropdown-menu list-unstyled msg_list overflow-h" role="menu">
                                        <li>
                                            <a href="http://docs.grandnode.com/" target="_blank">
                                                <i class="icon-book-open"></i>
                                                @T("Admin.Header.Documentation")
                                            </a>
                                        </li>
                                        <li>
                                            <a href="http://grandnode.com/boards" target="_blank">
                                                <i class="icon-bubbles"></i>
                                                @T("Admin.Header.Community")
                                            </a>
                                        </li>
                                        <li>
                                            <a href="javascript:;">
                                                <i class="fa fa-dot-circle-o"></i> grandnode @currentVersion
                                            </a>
                                        </li>
                                    </ul>
                                </li>
                                <li role="presentation" class="dropdown">
                                    <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                                        <i class="icon-settings"></i>
                                    </a>
                                    <ul id="menu1" class="dropdown-menu list-unstyled msg_list overflow-h" role="menu">
                                        @if (canManageMaintenance)
                                        {
                                            <li>
                                                <a href="@Url.Action("ClearCache", "Common", new { memory = true, returnurl = webHelper.GetRawUrl(this.Context.Request)})">
                                                    <i class="icon-refresh"></i>
                                                    @T("Admin.Header.ClearCacheMemory")
                                                </a>
                                            </li>
                                            @if (grandConfig.RedisCachingEnabled)
                                            {
                                                <li>
                                                    <a href="@Url.Action("ClearCache", "Common",  new { memory = false, returnurl = webHelper.GetRawUrl(this.Context.Request)})">
                                                        <i class="icon-refresh"></i>
                                                        @T("Admin.Header.ClearCacheRedis")
                                                    </a>
                                                </li>
                                            }
                                            <li>
                                                <a href="@Url.Action("RestartApplication", "Common", new { returnurl = webHelper.GetRawUrl(this.Context.Request) })" id="restart-application">
                                                    <i class="icon-reload"></i>
                                                    @T("Admin.Header.RestartApplication")
                                                </a>
                                            </li>
                                        }
                                    </ul>
                                </li>
                                <li>
                                    <a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                        <img src="~/administration/build/images/avatar.png" alt="">

                                        @if (currentCustomer != null && currentCustomer.IsRegistered())
                                        {
                                            <div class="username-hide-on-mobile">
                                                @(usernamesEnabled ? currentCustomer.Username : currentCustomer.Email)
                                            </div>

                                        }
                                        <span class="fa fa-angle-down"></span>
                                    </a>

                                    <ul class="dropdown-menu dropdown-menu-default">
                                        <li>
                                            <a href="@Url.Action("Edit", "Customer", new { id = currentCustomer.Id, area = "Admin" })">
                                                <i class="icon-user"></i> @T("Admin.Header.Profile")
                                            </a>
                                        </li>
                                        <li>
                                            <a href="@Url.Action("Logout", "Customer", new { area = "" }, null)">
                                                <i class="icon-logout"></i> @T("Admin.Header.Logout")
                                            </a>
                                        </li>
                                    </ul>
                                </li>


                                @await Component.InvokeAsync("CommonLanguageSelector")
                                <li class="dropdown" role="presentation">
                                    <span id="searchIcon" class="searchIcon dropdown-toggle">
                                        <i class="icon-magnifier"></i>
                                    </span>
                                </li>
                            </ul>
                        </nav>
                    </div>
                    <div class="clear"></div>
                </div>
                <vc:admin-widget widget-zone="header_navbar_after" additional-data="null" />
            }

            <div class="right_col" role="main">
                <partial name="Notifications" />
                @RenderBody()
            </div>
            <div class="throbber">
                <div class="curtain">
                </div>
                <div class="curtain-content">
                    <div>
                        <h1 class="throbber-header">Wait...</h1>
                        <div class="spinner active">
                            <svg style="width:100px; height:100px" viewBox="0 0 64 64">
                                <circle cx="32" cy="32" r="29" fill="none" stroke-width="3" stroke-miterlimit="10"></circle>
                            </svg>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    @Html.GrandCssFiles(this.Url, ResourceLocation.Footer)
    @Html.GrandScripts(this.Url, ResourceLocation.Footer)
    <div class="page-footer">
        <div class="page-footer-inner">
            <a href="https://grandnode.com/" target="_blank">2019 © Powered by GrandNode.</a>
        </div>
        <div class="scroll-to-top">
            <i class="icon-arrow-up"></i>
        </div>
    </div>
    <script>
            $(document).ready(function () {
                $("#restart-application").click(function (e) {
                    event.preventDefault();
                    showThrobber('@Html.Raw(JavaScriptEncoder.Default.Encode(T("Admin.Header.RestartApplication.Progress").Text))');
                    $("html, body").animate({ scrollTop: 0 }, 400);
                    $.get($(this).attr("href"), function (data) { });
                    setTimeout(function () {
                        location.reload();
                    }, 10000);
                });
            });
    </script>
</body>
</html>